package com.baomidou.springboot.service.impl;



import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.springboot.entity.EmailDetail;
import com.baomidou.springboot.mapper.EmailMapper;
import com.baomidou.springboot.service.EmailService;
import com.baomidou.springboot.util.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.UUID;


/**
 *
 * User 表数据服务层接口实现类
 *
 */
@Slf4j
@Service
public class EmailServiceImpl extends ServiceImpl<EmailMapper, EmailDetail> implements EmailService {

	@Override
    @Transactional(rollbackFor = Exception.class)
	public void insert(EmailDetail emailDetail, HttpServletRequest request) {
	    log.info("-------开始---------");
		if (emailDetail.getUploadFile().getSize() > 0) {
			// 将文件转换为文件地址
			FileUtil.deleteFile(request, emailDetail.getPicpath());
			String pic = FileUtil.upload(emailDetail.getUploadFile(), request);
			emailDetail.setPicpath(pic);
		}

		// 生成id
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		emailDetail.setId(uuid);
		emailDetail.setUploadFile(null);
        log.info("入库："+emailDetail.toString());
		int a = baseMapper.insert(emailDetail);
		System.out.println("------------------------:"+a);
	}
}